package com.ledi.guns.modular.ledipay.controller;

import io.swagger.annotations.Api;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ledi.guns.core.base.controller.BaseController;
import com.ledi.guns.core.base.tips.SuccessTip;
import com.ledi.guns.core.base.tips.Tip;
import com.ledi.guns.modular.ledipay.controller.req.H5ApplySchool.H5ApplySchoolInfo;
import com.ledi.guns.modular.ledipay.service.H5ApplySchoolService;

/**
 * 文件名称： com.ledi.guns.modular.ledipay.controller.H5ApplySchoolController.java<br/>
 * 初始作者： 许芬<br/>
 * 创建日期： 2018年3月1日<br/>
 * 功能说明： 移动端扫一扫申请乐校收 <br/>
 * =================================================<br/>
 * 修改记录：<br/>
 * 修改作者 日期 修改内容<br/>
 * ================================================<br/>
 * Copyright (橘子股份-幼儿事业部) 2017-2018.All rights reserved.<br/>
 */
@Api
@RestController
@RequestMapping("/restApi/h5Apply")
public class H5ApplySchoolController extends BaseController {

	protected final static Logger logger = LoggerFactory.getLogger(H5ApplySchoolController.class);
	@Autowired
	private H5ApplySchoolService h5ApplySchoolService;

	// 代理商添加学校的URL
	@Value("${add.agent.school.url}")
	private String addAgentSchoolUrl;

	/**
	 * @api {GET} /restApi/h5Apply/jumpH5 跳转到h5
	 * @apiGroup h5Apply
	 * @apiName jumpH5
	 * @apiParam userId 用户Id
	 * @apiParam agentId 代理商Id
	 * @apiParam agentName 代理商名称
	 * @apiParam sign 签名
	 * @apiVersion 1.2.0
	 */
	@RequestMapping(value = "/jumpH5", method = RequestMethod.GET)
	public void jumpH5(@RequestParam String userId, @RequestParam String agentId, @RequestParam String agentName,
			@RequestParam String sign, HttpServletResponse response) {

		try {
			response.sendRedirect(
					addAgentSchoolUrl + "?userId=" + userId + "&agentId=" + agentId
					+ "&agentName=" + agentName + "&sign=" + sign);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * @api {GET} /restApi/h5Apply/applySchoolSms 获取验证码
	 * @apiGroup h5Apply
	 * @apiName applySchoolSms
	 * @apiParam mobile 手机号码
	 * @apiSuccess code 返回编码
	 * @apiSuccess message 返回说明
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "message": "成功"
	 *                    }
	 * @apiVersion 1.2.0
	 */
	@RequestMapping(value = "/applySchoolSms/{mobile}", method = RequestMethod.GET)
	public Tip applySchoolSms(@PathVariable String mobile) {

		h5ApplySchoolService.applySchoolSms(mobile);
		return SuccessTip.buildSuccess();
	}

	/**
	 * @api {POST} /restApi/h5Apply/submitWork 提交工单
	 * @apiGroup h5Apply
	 * @apiName submitWork
	 * @apiParam agentId 代理商ID
	 * @apiParam userId 用户ID
	 * @apiParam sign 签名
	 * @apiParam schoolName 学校名称
	 * @apiParam schoolContactPeople 学校联系人
	 * @apiParam contactTel 联系人手机号
	 * @apiParam mailBox 学校对公邮箱
	 * @apiParam smsCode 短信验证码
	 * @apiParam isAlipayPay （1：开通支付宝支付，2：不开通支付宝支付）
	 * @apiParam isWeixinPay （1：开通微信，2：不开通微信支付）
	 * @apiParam alipayNumber 学校对公支付宝账号
	 * @apiParam schoolNature 学校性质（1公立学校，2私立学校）
	 * @apiParam photoOrganizeFrameworkUrl 组织结构代码证书或者三证合一证书
	 * @apiParam photoPermitUrl; 公立学校《事业单位法人证书》私立学校《办学许可证》
	 * @apiParam photoOpenAccountUrl 开户许可证
	 * @apiParam photoIdPositiveUrl 身份证正面
	 * @apiParam photoIdOppositeUrl 身份证反面
	 * @apiSuccess code 返回编码
	 * @apiSuccess message 返回说明
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "message": "成功"
	 *                    }
	 * @apiVersion 1.3.0
	 */
	@RequestMapping(value = "/submitWork", method = RequestMethod.POST)
	public Tip submitWork(@RequestBody @Valid H5ApplySchoolInfo h5ApplySchoolInfo) {

		h5ApplySchoolService.submitWork(h5ApplySchoolInfo);
		return SuccessTip.buildSuccess();
	}
}
